package com.rs.admin.sys.org.controller;


import com.rs.admin.sys.base.annotation.PageParamsAnnotation;
import com.rs.admin.sys.org.entity.User;
import com.rs.admin.sys.org.entity.UserDetail;
import com.rs.admin.sys.org.service.UserService;
import com.rs.admin.sys.org.vo.UserVo;
import com.rs.common.controller.BaseController;
import com.rs.common.entity.PageParams;
import com.rs.common.page.PageResult;
import com.rs.common.utils.BCrypt.BCryptUtil;
import com.rs.common.utils.constant.Constant;
import com.rs.common.utils.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author hedonglin
 * @since 2017-12-20
 */
@RestController
@RequestMapping("/org/users")
@Api(value = "用户接口")
public class UserController extends BaseController {
    @Autowired
    private UserService userService;

    /**
     * 因为搜索条件较多，做成post请求，不违反restful风格
     * @param params
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "登录",notes = "登录说明")
    @ApiImplicitParam(paramType = "query", dataType="string", name = "username", value = "用户名", required = true)
    public R list(@RequestBody PageParams params) {
        PageResult list = userService.findList(params);
        return R.ok().put("page",list);
    }

    @PostMapping("")
    public R add(@RequestBody UserVo user) {
        boolean b = userService.add(user);
        return R.ok().put("user",user);
    }

    @PutMapping("/{id}")
    public R update(@PathVariable Long id,@RequestBody UserVo user) {
        //对象中id不存在时设置路径中的
        if (id>0 && user.getId()==null){
            user.setId(id);
        }
        boolean b = userService.update(user);

        return R.ok().put("user",user);
    }




}

